<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<title>审批</title>
	<link rel="stylesheet" href="assets/libs/layui/css/layui.css" />
	<style>

		.login-header {
			color: rgba(0, 0, 0, .85) !important;
			padding: 5% 0;
			text-align: center;
		}
		.buttongroup {
			display: flex;
			margin-top: 10%;
		}

		.buttongroup button {
			width: 100%;
			height: 45px;
		}

		.order_massage{
			margin-bottom: 30px;
		}
		.order_massage li{
			overflow: hidden;
			margin-bottom: 10px;
			color: #000;
		}
		.order_massage li:last-child{
			border-bottom: none;
		}
		.order_massage_title{
			float: left;
			width: auto;
		}
		.layui-input-block{
			margin: 0px;
			display: flex;
    		justify-content: center
		}
		.main_content_wrap{
			margin: 20px 0px;
			display: flex;
			flex-direction: column;
			align-items: center;
		}
		.layui-form{
			display: flex;
			flex-direction: column;
			width: 32%;
		}
        @media screen and (max-width: 800px) {
			.layui-form{
				display: flex;
				flex-direction: column;
				width: auto !important;
			}
			.main_content_wrap p{
				width: 63% !important;
				margin-bottom: 15px;
			}

		}
		.layui-form-item{
			display: flex;
		}
		.main_content_wrap p{
			width: 28%;
			margin-bottom: 15px;
		}
		.opendata-show{
			height: 38px;
			line-height: 38px;
		}
	</style>
</head>

<body>
	<div class="body">
		<div class="login-header">
			<h2 style="font-weight: 400;letter-spacing: 3px; font-size: 30px">选择金额审批人</h2>
		</div>
		<div class="layui-fluid content_box">
			<div class="main_content_wrap">
				<p>审批规则</p>
				<div class="layui-input-block"  id="detailView"></div>
				<form lay-filter="modifyForm" class="layui-form model-form">
					<div class="layui-form-item">
						<label class="layui-form-label">审批老师</label>
						<div class="layui-input-inline">
							<div class="layui-input" id="selUser">
								<ww-open-data class="opendata-show" type="userName" openid="" id="userData"></ww-open-data>
							</div>
						</div>
						<input name="check_teacher_id" id="check_teacher_id" hidden />
					</div>
					<div class="layui-form-item text-center buttongroup">
						<button type="button" lay-filter="modifyFormSubmit" lay-submit
							class="layui-btn site-demo-active">保存</button>
					</div>
				</form>
			</div>
		</div>
	</div>
	<script type="text/javascript" src="assets/libs/layui/layui.js"></script>
	<script type="text/javascript" src="assets/js/config.js"></script>
	<script type="text/javascript" src="assets/js/wechatApi.js"></script>
	<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
	<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>

	<script src="https://wwcdn.weixin.qq.com/node/open/js/wecom-jssdk-1.3.1.js"></script>
	<script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js" referrerpolicy="origin"></script>
	<script id="detail" type="text/html">
		<ul class='order_massage'>
			{{#  layui.each(d, function(index, item){ }}
				<li>
					<span class="order_massage_title">{{item}}</span>
				</li>
			{{#  }); }}
		</ul>
	</script>
	<script>
		layui.config({
			base: 'assets/module/'
		}).use(['jquery', 'form','layer','laytpl'], function () {
			var $ = layui.jquery;
			var form = layui.form;
			var layer = layui.layer;
			var laytpl = layui.laytpl;

			var id = getUrlParam('id');
			var opt_type = getUrlParam('type');
			let userMsg = JSON.parse(localStorage.getItem("userMsg"));
			toRegister(userMsg);
			getMoneyCheckList();

			form.render();
			//监听提交
			form.on('submit(modifyFormSubmit)', function (data) {
				var DISABLED = 'layui-btn-disabled';
				// 增加样式
				$('.site-demo-active').addClass(DISABLED);
				// 增加属性
				$('.site-demo-active').attr('disabled', 'disabled');
				var form_data = data.field;
				form_data.opt_json_content = JSON.stringify(form_data);
				form_data.knowledge_id = id
				form_data.opt_type = opt_type?opt_type:3
				form_data.opt_userid = userMsg.UserId;
				form_data.opt_deptment = Array.isArray(userMsg.department)?userMsg.department.join(','):userMsg.department;
				let newobj = typeChange(form_data);
				$.post(serverUrl + 'Knowledge/modifyInfo.html', newobj, function (res) {
					if (res.success === true) {
						layer.msg('提交成功', { icon: 1, time: 300 }, function () {
							window.location.href = `detail.html?id=`+id;
						});
					} else {
						layer.msg(res.msg, { icon: 2 });
						$('.site-demo-active').removeClass(DISABLED);
						$('.site-demo-active').removeAttr('disabled');
					}
				}, 'json');
				return false;
			});

			$('#selUser').on('click', function () {
				document.getElementById('userData').setAttribute('openid', '');
				WWOpenData.bind(document.querySelector('ww-open-data'));
				selectEnterpriseContact('user','single',[],[],
					function (res) {
						const openid = res.ids[0]
						$('#check_teacher_id').val(openid)
						document.getElementById('userData').setAttribute('openid', openid);
						WWOpenData.bind(document.querySelector('ww-open-data'));
						form.render();
					},
					function (err) {
						console.log('选择失败：', err)
					}
				)
			});

			function getMoneyCheckList() {
				var moneyCheckText = [];
				$.get(serverUrl + 'Common/getList.html', {type:'money_check'}, function (res) {
					for (var i = 0; i < res.obj.length; i++) {
						var info = '';
						if(i>0 && res.obj[i-1].name){
							info = moneyHandle(res.obj[i-1].name)+'及以上';
						}
						if(res.obj[i].name){
							if(info){
								info += '—'
							}
							info += moneyHandle(res.obj[i].name)+'（不含）';
							if(i==0){
								info += '以下'
							}
						}
						info += res.obj[i].common;
						moneyCheckText.push(info)
					}
					var orderDetail = document.getElementById('detail');
					var getOrderTpl = orderDetail.innerHTML;
					var orderView = document.getElementById('detailView');
					laytpl(getOrderTpl).render(moneyCheckText, function(html){
						orderView.innerHTML = html;
					});
				}, 'json')
			}
			function moneyHandle(num){
				var moeny = '';
				if(num > 10000){
					moeny = num/10000 + '万元'
				}else{
					moeny = num +'元'
				}
				return moeny;
			}
		});
	</script>
</body>

</html>